/**
 * @author Miguel Diaz//257835
 */

package main;



import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.Mongo;
import com.mongodb.MongoException;
import dao.AdministratorMongoCtrl;
import dao.exceptions.NonexistentEntityException;
import dao.exceptions.PreexistingEntityException;
import entity.Administrator;
import java.net.UnknownHostException;


public class App 
{
    public static void main( String[] args )
    {
        try {
			// connect to mongoDB, ip and port number
			Mongo mongo = new Mongo();
 
			// get database from MongoDB,
			// if database doesn't exists, mongoDB will create it automatically
			DB db = mongo.getDB("HU15(1)");
 
			// Get collection from MongoDB, database named "yourDB"
			// if collection doesn't exists, mongoDB will create it automatically
			DBCollection administratorCollection = db.getCollection("Administrator");
                        DBCollection changelogCollection= db.getCollection("ChangeLog");
                        DBCollection commertialEstablishmentCollection=db.getCollection("CommertialEstablishment");
                        
                        
                        AdministratorMongoCtrl admMongoController=new AdministratorMongoCtrl(administratorCollection);
                        
                        Administrator dummie=new Administrator();
                        dummie.setDocument(9000);
                        dummie.setMiddleName("coso");
                        dummie.setName("piro");
                        dummie.setPassword("adkjfl213kks");
                        dummie.setSecondName("james");
                        dummie.setStatus("active");
                        dummie.setUser("piromano");
                        
                        Administrator dummie2=new Administrator();
                        dummie2.setDocument(11111111);
                        dummie2.setMiddleName("assss");
                        dummie2.setName("paaaairo");
                        dummie2.setPassword("adkjflpppppks");
                        dummie2.setSecondName("james2");
                        dummie2.setStatus("actives");
                        dummie2.setUser("klmnm");
                        
                        Administrator dummie3=new Administrator();
                        dummie3.setDocument(000);
                        dummie3.setMiddleName("assss");
                        dummie3.setName("paaaairo");
                        dummie3.setPassword("adkjflpppppks");
                        dummie3.setSecondName("james2");
                        dummie3.setStatus("actives");
                        dummie3.setUser("klmnm");
                        
                        
                        admMongoController.findAdministratorEntities();
            try {
                admMongoController.create(dummie);
            } catch (PreexistingEntityException ex) {
                System.out.println(ex.getMessage());
            }

                        System.out.println("\n");
                        admMongoController.findAdministratorEntities();
            try {
                admMongoController.edit(dummie3, dummie2);
            } catch (NonexistentEntityException ex) {              
                System.out.println(ex.getMessage());
            } catch (Exception ex) {
                System.out.println(ex.getMessage());
            }
                System.out.println("uh!\n");
            admMongoController.findAdministratorEntities();
            System.out.println("uh!\n");
            try {
                admMongoController.destroy(dummie3);
            } catch (NonexistentEntityException ex) {
                System.out.println(ex.getMessage());
            }
            admMongoController.findAdministratorEntities();
            
 
 
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (MongoException e) {
			e.printStackTrace();
		}
        
    }
}
